package com.skytech.tax.customsdatawarehouse.singlewindow.taxhandle.domain.dao;

import com.skytech.tax.customsdatawarehouse.singlewindow.taxhandle.domain.entity.TaxBillSub;
import org.joda.time.DateTime;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @author Lianhong
 * @since 2022/6/30
 */
@Repository
public class TaxBillSubDao {

    @Resource
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    private String saveTaxBillSubSql = "INSERT INTO sw_tax_bill_sub (swTaxId, taxCatgId, taxSub, storageTime) VALUES (:swTaxId, :taxCatgId, :taxSub, :storageTime)";

    public void save(TaxBillSub sub) {
        sub.setStorageTime(DateTime.now().toString("yyyy-MM-dd HH:mm:ss"));
        this.namedParameterJdbcTemplate.update(this.saveTaxBillSubSql, new BeanPropertySqlParameterSource(sub));
    }

    private String deleteTaxBillSubSql = "DELETE FROM sw_tax_bill_sub WHERE swTaxId = ?";

    public void delete(String swTaxId) {
        this.namedParameterJdbcTemplate.getJdbcOperations().update(this.deleteTaxBillSubSql, swTaxId);
    }
}
